<?php
/**
 * Created by PhpStorm.
 * User: jswei
 * Date: 2018/5/3
 * Time: 13:48
 */
namespace app\first\controller;

use app\first\model\Carousel as CarouselModel;

/**
 * Class Carousel
 * @title 轮播图相关
 * @url /v1/carousel
 * @desc  有关于轮播图
 * @version 1.0
 * @package app\first\controller
 */
class Carousel extends Base{
    //是否开启授权认证
    public $apiAuth = false;
    //附加方法
    protected $extraActionList = [];
    //去除验证
    protected $skipAuthActionList = ['banners'];
    public function __construct(){
        parent::__construct();
    }

    /**
     * @title 获取轮播图
     * @method banners
     * @param int $type true 类型 0 0所有,1类目,2优惠,3资讯
     * @param int $cate_id true 一级栏目ID 0 0所有,其他指定
     * @param int $limit true 条数 4
     * @param string $order true 条数 desc asc|desc
     * @route('v1/carousel/banners','get')
     * @return \think\facade\Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\View|\think\response\Xml
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function banners($type=0,$cate_id=0,$limit=4,$order='desc'){
        $carousel = new CarouselModel;
        $map[] = ['status','eq',1];
        if($type){
            $map[] = ['type','eq',$type];
        }
        if($cate_id){
            $map[] = ['first_cate_id','eq',$cate_id];
        }
        $order = "order_id {$order},create_time {$order}";
        $list = $carousel->getList($map,$order,$limit);
        return $this->sendSuccess($list);
    }
}